home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / ex / ex8-8.c < prev    next >
C/C++ Source or Header  |  1990-05-15  |  1KB  |  48 lines

  1. // ex8-8.c -- sorting Patient records with a KeySortCltn
  2.  
  3. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex8-8.c,v 3.0 90/05/15 22:46:26 kgorlen Rel $
  4.  
  5. #include "Assoc.h"
  6. #include "Integer.h"
  7. #include "Iterator.h"
  8. #include "KeySortCltn.h"
  9. #include "String.h"
  10. #include "Patient.h"
  11.  
  12. main()
  13. {
  14. // Build list of Patient records
  15.     OrderedCltn cltn;
  16.     cltn.add(*new Patient("Smith John A.","111-22-3333",22222));
  17.     cltn.add(*new Patient("Fried Harry I.","123-45-6789",22221));
  18.     cltn.add(*new Patient("Chavez Maria G.","444-555-6666",22223));
  19.  
  20. // Three KeySortCltn collections for three different keys
  21.     KeySortCltn sort0(cltn.size());
  22.     KeySortCltn sort1(cltn.size());
  23.     KeySortCltn sort2(cltn.size());
  24.  
  25.     Iterator it(cltn);
  26.     while ( it++ )  {
  27.         Patient& p = *(Patient*)it();
  28.     
  29. // Sort Patient by name
  30.         sort0.addAssoc(*new String(p.name()),p);
  31.  
  32. // Sort Patient by social security number
  33.         sort1.addAssoc(*new String(p.ssn()),p);
  34.  
  35. // Sort Patient by zip code
  36.         sort2.addAssoc(*new Integer(p.zip()),p);
  37.     }
  38.  
  39.     cout << "SORT BY NAME:\n"
  40.          << sort0 << '\n' << endl;
  41.  
  42.     cout << "SORT BY SOCIAL SECURITY NUMBER:\n"
  43.          << sort1 << '\n' << endl;
  44.  
  45.     cout << "SORT BY ZIP CODE:\n"
  46.          << sort2 << '\n';
  47. }
  48.